/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.pay.web;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.text.TextUtils;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import com.qihoo.gamecenter.sdk.common.d.a;
import com.qihoo.gamecenter.sdk.common.d.a.a;
import com.qihoo.gamecenter.sdk.common.i.s;
import com.qihoo.gamecenter.sdk.common.web.view.WebViewer;
import com.qihoo.gamecenter.sdk.common.web.view.WebViewer.c;
import com.qihoo.gamecenter.sdk.pay.component.ProgressView;

public class WebPayView extends FrameLayout {
    private static final String TAG = "PayWebView";
    private Activity mContainer;
    private ProgressView mLoading;
    private WebViewer mWebViewer;
    private String mReqUrl;
    private String mRemoteCookie;
    private boolean mIsSuccess;
    private boolean mIsRepeatOrder;

    private WebPayView(Context paramContext) {
        super(paramContext);
        this.mIsSuccess = false;
        this.mIsRepeatOrder = false;
    }

    public WebPayView(Activity paramActivity, Intent paramIntent) {
        this(paramActivity);
        this.mContainer = paramActivity;
        this.mReqUrl = paramIntent.getStringExtra("pay_url");
        this.mRemoteCookie = paramIntent.getStringExtra("remote_cookie");
        initView();
        loadView();
    }

    private void initView() {
        setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
        setBackgroundColor(-592138);
        initWebViewer();
        initLoading();
        com.qihoo.gamecenter.sdk.pay.k.c.a("PayWebView", new Object[] { "init PayWebView complete" });
    }

    private void initWebViewer() {
        this.mWebViewer = new WebViewer(this.mContainer);
        this.mWebViewer.setReload(false);
        this.mWebViewer.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
        this.mWebViewer.setUserAgentString(s.u(this.mContainer));
        this.mWebViewer.setOnWebViewClient(new WebViewer.c() {
            public void a(WebView paramWebView, int paramInt, String paramString1, String paramString2) {
                com.qihoo.gamecenter.sdk.pay.k.c.a("PayWebView", new Object[] { "errorCode=",
                        Integer.valueOf(paramInt), ",description=", paramString1, ",failingUrl=", paramString2 });
            }

            public void a(WebView paramWebView, String paramString, Bitmap paramBitmap) {
                WebPayView.this.mLoading.a();
            }

            public void a(WebView paramWebView, String paramString) {
                WebPayView.this.mLoading.b();
                WebPayView.this.mWebViewer.requestFocus();
            }

            public boolean b(WebView paramWebView, String paramString) {
                return false;
            }
        });
        this.mWebViewer.addJavascriptInterface(new JSObject(this.mContainer), "Android");
        addView(this.mWebViewer);
    }

    private void initLoading() {
        this.mLoading = new ProgressView(this.mContainer);
        this.mLoading.setBackgroundColor(Color.argb(80, 40, 40, 40));
        this.mLoading.a(a.a(a.a.l));
        this.mLoading.setVisibility(0);
        addView(this.mLoading);
    }

    private void loadView() {
        com.qihoo.gamecenter.sdk.pay.k.c.a("PayWebView", new Object[] { "Start to load bbs url :", this.mReqUrl });
        if (TextUtils.isEmpty(this.mRemoteCookie))
            this.mWebViewer.setCookies(com.qihoo.gamecenter.sdk.common.a.c.g(), null, "/", ".360.cn");
        else
            this.mWebViewer.setCookies(com.qihoo.gamecenter.sdk.common.a.c.g(this.mRemoteCookie), null, "/", ".360.cn");
        this.mWebViewer.loadUrl(this.mReqUrl);
    }

    public void paySuccess() {
        Intent localIntent = this.mContainer.getIntent();
        localIntent.putExtra("status", this.mIsSuccess);
        localIntent.putExtra("repeat", this.mIsRepeatOrder);
        this.mContainer.setResult(-1, localIntent);
        this.mWebViewer.clear();
        this.mContainer.finish();
    }

    public void onDestory() {
        this.mWebViewer.destory();
    }

    public void onPause() {
        this.mWebViewer.pause();
    }

    public void onResume() {
        this.mWebViewer.resume();
    }

    public class JSObject {
        Context mContext;

        JSObject(Context paramContext) {
            this.mContext = paramContext;
        }

        @JavascriptInterface
        public void backToPayUI() {
            com.qihoo.gamecenter.sdk.pay.k.c.a("PayWebView", new Object[] { "JS CallBack: backToPayUI()" });
            WebPayView.this.paySuccess();
        }

        @JavascriptInterface
        public void paySucceed() {
            com.qihoo.gamecenter.sdk.pay.k.c.a("PayWebView", new Object[] { "JS CallBack: paySucceed()" });
            WebPayView.access$202(WebPayView.this, true);
            WebPayView.this.paySuccess();
        }

        @JavascriptInterface
        public void onPaySuccess() {
            com.qihoo.gamecenter.sdk.pay.k.c.a("PayWebView", new Object[] { "JS CallBack: onPaySuccess()" });
            WebPayView.access$202(WebPayView.this, true);
        }

        @JavascriptInterface
        public void onRepeatOrderError() {
            com.qihoo.gamecenter.sdk.pay.k.c.a("PayWebView", new Object[] { "JS CallBack: onRepeatOrderError()" });
            WebPayView.access$302(WebPayView.this, true);
        }

        @JavascriptInterface
        public void repeatOrderError() {
            com.qihoo.gamecenter.sdk.pay.k.c.a("PayWebView", new Object[] { "JS CallBack: repeatOrderError()" });
            WebPayView.access$302(WebPayView.this, true);
            WebPayView.this.paySuccess();
        }
    }
}